package com.lezhi.socialgram.util;

import com.lezhi.socialgram.enums.ResultEnum;
import com.lezhi.socialgram.exception.SocialGramException;

/**
 * Created by daizhen on 2017/3/16.
 */
public class ResultUtils {

    public static Result success(Object object) {
        return new Result(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), object);
    }

    public static Result success() {
        return success(null);
    }

    public static Result error(ResultEnum resultEnum) {
        return new Result(resultEnum.getCode(), resultEnum.getMessage());
    }

    public static Result error(ResultEnum resultEnum, String extra) {
        return new Result(resultEnum.getCode(), resultEnum.getMessage() + extra);
    }

    public static Result error(SocialGramException exception) {
        return new Result(exception.getCode(), exception.getMessage());
    }
}
